package com.spring.sso.config.security.mvc;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * thymeleaf 试图配置, 配置对应resources目录下的页面试图，如果前后端不分离的项目中,不配置此那么在
 * spring security中的http.formLogin()表单配置将会无法自动在验证不通过时跳转到登陆页面
 * @author : pangfuzhong
 * @description
 * @date : 2021/9/18 08:53
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    /**
     * 配置静态页面请求处理
     */
    /*@Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix(null);
        viewResolver.setSuffix(null);
        registry.viewResolver(viewResolver);
        registry.order(1);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/templates/web/");
    }*/

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //registry.addViewController("/static/home").setViewName("home");
        //registry.addViewController("/static/hello").setViewName("hello");
        registry.addViewController("/templates/login").setViewName("login");
    }
}
